package vues;

import java.awt.BasicStroke;
import java.awt.Color;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Rectangle2D;

import sourceCode.Embranchement;

public class VueEmbranchement extends Vue {

    private Embranchement embranchement;
    private VueAeroport vueAeroport;
    private Color couleurNormal = new Color(250, 130, 60);
    private Rectangle2D.Double rect;

    private int diametreEmbranchement = 20;

    public VueEmbranchement(VueAeroport v, Embranchement e) {
        super();
        this.embranchement = e;
        this.vueAeroport = v;
        this.rect = createRectangle();
    }

    public Rectangle2D.Double createRectangle() {
        Point coordonneePixels = this.vueAeroport.convertCoordonnesToPixels(embranchement.getCoordonnees());
        return new Rectangle2D.Double(coordonneePixels.getX() - this.diametreEmbranchement / 2,
                                      coordonneePixels.getY() - this.diametreEmbranchement / 2, this.diametreEmbranchement,
                                      this.diametreEmbranchement);
    }

    @Override
    public boolean estCliquee(int x, int y) {
        return this.rect.contains(x, y);
    }

    @Override
    public void dessiner(Graphics g) {
        Color cTemp = g.getColor();
        Graphics2D g2 = (Graphics2D)g;
        g2.setStroke(new BasicStroke());
        g2.setColor(this.couleurNormal);
        g2.drawRect((int)this.rect.getX(), (int)this.rect.getY(), (int)this.rect.getWidth(), (int)this.rect.getHeight());
        g.setColor(cTemp);
        return;
    }

    @Override
    public String getType() {
        return "VueEmbranchement";
    }

    public Rectangle2D.Double getRect() {
        return this.rect;
    }
}
